import request from '@/utils/request'

export type DictDataVO = {
  id: number | undefined
  sort: number | undefined
  label: string
  value: string
  dictType: string
  status: number
  colorType: string
  cssClass: string
  remark: string
  createTime: Date
  children: DictDataVO[]
}

// 查询字典数据（精简)列表
export const getSimpleDictDataList = () => {
  return request({
    url: '/system/dict-data/simple-list',
    method: 'GET',
  })
}

// 查询字典数据列表
export const getDictDataPage = (params: any) => {
  return request({
    url: '/system/dict-data/page',
    method: 'GET',
    params,
  })
}

// 查询字典数据详情
export const getDictData = (id: number) => {
  return request({
    url: `/system/dict-data/get?id=${id}`,
    method: 'GET',
  })
}

export const dictDataSaveOrUpdate = (data: DictDataVO) => {
  if (data.id != null && data.id) {
    return request({
      url: '/system/dict-data/update',
      method: 'PUT',
      data,
    })
  } else {
    return request({
      url: '/system/dict-data/create',
      method: 'POST',
      data,
    })
  }
}

// 新增字典数据
export const createDictData = (data: DictDataVO) => {
  return request({
    url: '/system/dict-data/create',
    method: 'POST',
    data,
  })
}

// 修改字典数据
export const updateDictData = (data: DictDataVO) => {
  return request({
    url: '/system/dict-data/update',
    method: 'PUT',
    data,
  })
}

// 删除字典数据
export const deleteDictData = (id: number) => {
  return request({
    url: `/system/dict-data/delete?id=${id}`,
    method: 'DELETE',
  })
}

// 导出字典类型数据
export const exportDictData = (params) => {
  return request({
    url: '/system/dict-data/export',
    method: 'GET',
    responseType: 'blob',
    params,
  })
}

// 根据类型读取字典数据
export const getDictType = (params: any) => {
  return request({
    url: '/system/dict-data/getDictType',
    method: 'get',
    params,
  })
}

// 字典类型的树形结构
export const getDictTypeTree = (params?: any) => {
  return request({
    url: '/system/dict-type/tree-flat',
    method: 'get',
    params,
  })
}
